package com.h.ssRoom.controller;

<<<<<<< HEAD
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.h.ssRoom.model.Appoints;
import com.h.ssRoom.repo.AppointsRepo;

=======
import java.sql.Timestamp;
import java.sql.Date;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.h.ssRoom.model.Appoints;
import com.h.ssRoom.repo.AppointsRepo;


>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
@RestController
@RequestMapping(path="/api",produces="application/json;charset=utf-8")
public class AppointsController {
	@Autowired
	private AppointsRepo appointsRepo;
	
	//获取预约记录
	@PostMapping(value="/appointRecord")
	public List<Appoints> getAppoints(@RequestParam(value="customerID",required=true) String customerID) {
		List<Appoints> result=appointsRepo.getAppointsByID(customerID);
<<<<<<< HEAD
=======
		System.out.println(result);
>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
		return result;
	}
	
	//新增预约记录
	@PostMapping(value="/AddRecord")
	public Map<String, Object> insertAppoints(@RequestParam(value="customerID",required=true) String customerID,
			@RequestParam(value="ssRoomID",required=true) Integer ssRoomID,
			@RequestParam(value="seatID",required=true) Integer seatID,
<<<<<<< HEAD
			@RequestParam(value="startTime",required=true) Date startTime,
			@RequestParam(value="studyLen",required=true) Integer studyLen) {
        Map<String,Object> result = new HashMap<>();
        Appoints appoint=new Appoints();
        appoint.setCustomerID(customerID);
        appoint.setSsRoomID(ssRoomID);
        appoint.setSeatID(seatID);
        appoint.setStartTime(startTime);
        appoint.setStudyLen(studyLen);
        appointsRepo.save(appoint);
=======
			@RequestParam(value="startTime",required=true) String startTime,
			@RequestParam(value="studyLen",required=true) Integer studyLen) {
		//String转Timestamp
		Timestamp ts = Timestamp.valueOf(startTime);
		System.out.println("新增预约记录");
        Map<String,Object> result = new HashMap<>();
        appointsRepo.insertAppointsByID(customerID, ssRoomID, seatID, ts, studyLen);
>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
        result.put("status","success");
		List<Appoints> appointList=appointsRepo.getAppointsByID(customerID);
		if(appointList.size()==0) {
			result.put("status", "插入失败");
			return result;
		} else {
            result.put("status", "插入成功");
            return result;
		}
	}
	
    //学习记录
//    @GetMapping("/study_record")
//    public List<Appoints> studyRecord(@RequestParam(value = "customerID",required = true) String customerID){
//        List<Appoints> appointsList = appointsRepo.studyRecord(customerID);
//        return appointsList;
//    }
<<<<<<< HEAD
=======





>>>>>>> 71d11a30821e4a369fe163d5c0d88106681576b3
}
